//
//  WubiLessonsViewController.m
//  Fozua
//
//  Created by MingmingSun on 2016/11/21.
//  Copyright © 2016年 Sunmingming. All rights reserved.
//

#import "WubiLessonsViewController.h"
#import "WubiLessonViewController.h"

@interface WubiLessonsViewController()

@end

@implementation WubiLessonsViewController

- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
	self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
	if (self) {
	}
	return self;
}

- (void)viewDidLoad
{
	[super viewDidLoad];
	// Custom initialization
	UIImageView *bgImageView = [[UIImageView alloc] initWithFrame:self.view.bounds];
	bgImageView.image = [UIImage imageNamed:@"wubiMainBG"];
	bgImageView.contentMode = UIViewContentModeScaleToFill;
	self.tableView.backgroundView = bgImageView;
	self.tableView.backgroundColor = [UIColor clearColor];
	self.tableView.separatorStyle = UITableViewCellSeparatorStyleNone;
}

-(void)viewWillAppear:(BOOL)animated{
	[super viewWillAppear:animated];
	[self.tableView reloadData];
}

-(void)dealloc
{
}

- (void)didReceiveMemoryWarning
{
	[super didReceiveMemoryWarning];
	// Dispose of any resources that can be recreated.
}

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
	// Return the number of sections.
	return 1;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
	// Return the number of rows in the section.
	return 6;
}

-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
	return 80.0f;
}

-(UITableViewCell*)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
	UITableViewCell *cell;
	static NSString *inde = @"normalwubiid";
	cell = [tableView dequeueReusableCellWithIdentifier:inde];
	if (cell == nil) {
		cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:inde];
		cell.backgroundColor = [UIColor clearColor];
		cell.detailTextLabel.numberOfLines = 0;
	}
	NSInteger nowTag = indexPath.row + 1;
	UIImage *toImage = [UIImage imageNamed:[NSString stringWithFormat:@"wubiButton%ld",nowTag]];
	cell.imageView.image = toImage;
	if(nowTag > [APPALL.mydefaults integerForKey:@"nowLevel"] && nowTag <= 6)
	{
		cell.textLabel.textColor = [UIColor lightGrayColor];
		cell.detailTextLabel.textColor = [UIColor lightGrayColor];
		cell.textLabel.highlightedTextColor = [UIColor lightGrayColor];
		cell.detailTextLabel.highlightedTextColor = [UIColor lightGrayColor];
	}else{
		cell.textLabel.textColor = [UIColor blackColor];
		cell.detailTextLabel.textColor = [UIColor blackColor];
		cell.textLabel.highlightedTextColor = [UIColor blackColor];
		cell.detailTextLabel.highlightedTextColor = [UIColor blackColor];
	}
	switch (nowTag) {
		case 1:
			cell.textLabel.text = @"五笔输入法概念";
			cell.detailTextLabel.text = @"了解五笔输入法的概念和基本知识。";
			break;
		case 2:
			cell.textLabel.text = @"字根分区分布";
			cell.detailTextLabel.text = @"了解五笔字根的概念，以及字根的排列和分布。";
			break;
		case 3:
			cell.textLabel.text = @"五笔拆字原则";
			cell.detailTextLabel.text = @"了解如何正确地将汉字按顺序拆分为字根。";
			break;
		case 4:
			cell.textLabel.text = @"单字的输入方法";
			cell.detailTextLabel.text = @"在字根相关知识的基础上，学习使用五笔打单字。";
			break;
		case 5:
			cell.textLabel.text = @"简码的输入方法";
			cell.detailTextLabel.text = @"五笔的简码原则可以让你更快的输入一些常用汉字。";
			break;
		case 6:
			cell.textLabel.text = @"词语的输入方法";
			cell.detailTextLabel.text = @"强化学习！在单字输入的基础上学习如何打出词语。";
			break;
		default:
			break;
	}
	return cell;
}

-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
	NSInteger selectedTag = indexPath.row + 1;
	if(selectedTag > [APPALL.mydefaults integerForKey:@"nowLevel"] && selectedTag <= 6)
	{
		UIAlertController *vc = [UIAlertController alertControllerWithTitle:@"尚未开启" message:@"本教程尚未开启，请先学习前几章功能！" preferredStyle:UIAlertControllerStyleAlert];
		//    vc.view.backgroundColor = [UIColor goldColor];
		UIAlertAction *cancelAction = [UIAlertAction actionWithTitle:@"好的" style:UIAlertActionStyleCancel handler:nil];
		[vc addAction:cancelAction];
		[self presentViewController:vc animated:NO completion:nil];
	}
	else
	{
		UITableViewCell *cell = [tableView cellForRowAtIndexPath:indexPath];
		WubiLessonViewController *vc = [[WubiLessonViewController alloc] initWithLessonIndex:(int)selectedTag];
		vc.title = cell.textLabel.text;
		[self.navigationController pushViewController:vc animated:YES];
	}
}

@end
